package io.xccit.race.service.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import io.xccit.race.mapper.RaceCompetitionMapper;
import io.xccit.race.domain.RaceCompetition;
import io.xccit.race.service.IRaceCompetitionService;

@Service
public class RaceCompetitionServiceImpl implements IRaceCompetitionService {

    @Autowired
    private RaceCompetitionMapper mapper;

    @Override
    public RaceCompetition selectRaceCompetitionById(Long id) {
        return mapper.selectRaceCompetitionById(id);
    }

    @Override
    public List<RaceCompetition> selectRaceCompetitionList(RaceCompetition query) {
        return mapper.selectRaceCompetitionList(query);
    }

    @Override
    public int insertRaceCompetition(RaceCompetition entity) {
        if (entity.getDelFlag() == null) {
            entity.setDelFlag("0");
        }
        // 默认设置为可报名状态
        if (entity.getCompetitionStatus() == null) {
            entity.setCompetitionStatus(1);
        }
        return mapper.insertRaceCompetition(entity);
    }

    @Override
    public int updateRaceCompetition(RaceCompetition entity) {
        return mapper.updateRaceCompetition(entity);
    }

    @Override
    public int deleteRaceCompetitionById(Long id) {
        return mapper.deleteRaceCompetitionById(id);
    }

    @Override
    public int deleteRaceCompetitionByIds(Long[] ids) {
        return mapper.deleteRaceCompetitionByIds(ids);
    }

    // 统计方法
    @Override
    public Long selectCount() {
        return mapper.selectCount();
    }

    @Override
    public List<Map<String, Object>> selectCompetitionTypeDistribution() {
        return mapper.selectCompetitionTypeDistribution();
    }

    @Override
    public List<Map<String, Object>> selectCompetitionTimeDistribution() {
        return mapper.selectCompetitionTimeDistribution();
    }

    @Override
    public List<Map<String, Object>> selectNationalCompetitionDistribution() {
        return mapper.selectNationalCompetitionDistribution();
    }

    // 新增方法
    @Override
    public List<RaceCompetition> selectAvailableCompetitions() {
        return mapper.selectAvailableCompetitions();
    }

    @Override
    public List<RaceCompetition> selectCompetitionsByStatus(Integer competitionStatus) {
        return mapper.selectCompetitionsByStatus(competitionStatus);
    }

    @Override
    public List<Map<String, Object>> selectCompetitionStatusCount() {
        return mapper.selectCompetitionStatusCount();
    }
}


